package com.huluobo.mvvm_base.mvvm.db;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.huluobo.mvvm_base.mvvm.bean.UserBeanResult;

import java.util.List;

import io.reactivex.Observable;

/**
 * Created by LC on 2024/2/27.
 * Dao Database 转换为 Object 数据库的内容(表中)转换为实体类
 * Room中的Dao主要存放的是增删改查的方法
 */
@Dao
public interface UserDao {
    //新增,onConflict设置冲突策略 (REPLACE 替换,ABORT 回滚,IGNORE 忽略)
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertUserInfo(UserBeanResult.UserBean userBean);

    //删除
    @Delete
    void deleteUserInfo(UserBeanResult.UserBean userBean);

    //修改
    @Update
    void updateUserInfo(UserBeanResult.UserBean userBean);

    //查询表中所有数据
    @Query("select * from user_info")
    List<UserBeanResult.UserBean> queryUserInfo();

    //where后的username是bean中的属性,等号后的:username是参数名
    @Query("select * from user_info where username=:username")
    Observable<UserBeanResult.UserBean> queryUserInfoByName(String username);
}
